package org.springblade.modules.mes.base.controller;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 产品BOM信息 控制器
 *
 * @author BladeX
 * @since 2021-03-11
 */
@RestController
@AllArgsConstructor
@RequestMapping("/v1/web")
@Slf4j
public class WebClientController {


	@GetMapping("/urls")
	public Map<String, String> repair(HttpServletRequest request) throws Exception {
		Map<String, String> urlMaps = new HashMap<>();
		String uri = request.getRequestURI();
		String url = request.getRequestURL().toString();
		String basePath = url.substring(0, url.length() - uri.length());
		String ws = basePath.replace("https", "ws");
		ws = ws.replace("http", "ws");
		urlMaps.put("websocket", ws + "/websocket");
		urlMaps.put("baseUrl", "/api");
		urlMaps.put("baseFullUrl", basePath + "/api");
		return urlMaps;
	}

}
